package com.base.common.view.adapter.ada;

import android.view.View;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.LifecycleOwner;

import com.base.common.view.adapter.connector.BaseViewHolder;
import com.base.common.view.adapter.connector.BaseItemTypeInterface;

/**
 * 单一类型item的
 * 必须为虚类 {@link BaseRVAdapter#putMultiItemType(BaseItemTypeInterface)}用了反射
 *
 * @param <T>
 * @param <D>
 */
public abstract class SingleRecyclerAdapter<T, D extends ViewDataBinding> extends GeneralRecyclerAdapter implements BaseItemTypeInterface<T, D> {

    private int layRes;

    public SingleRecyclerAdapter() {

    }

    public SingleRecyclerAdapter(LifecycleOwner lifecycleOwner) {
        super(lifecycleOwner);
    }

    public SingleRecyclerAdapter(@LayoutRes int layRes) {
        this.layRes = layRes;
        super.init();
    }


    public T getListBean(int position) {
        if (position <= getLastPosition() && position >= getFirstPosition()) {
            return (T) getItemBean(position);
        } else return null;
    }


    @Override
    public int getLayoutId() {
        return layRes;
    }


    @Override
    public int getItemViewType() {
        return TYPE_CHILD;
    }

    @Override
    public boolean isCurrentItemType(int position, @NonNull T bean) {
        return true;
    }


    @Override
    public boolean isFullSpanType() {
        return false;
    }

    @Override
    public void initMultiItemType() {
        putMultiItemType(this);
    }


    @Override
    public void onCreateViewHolder(D binding, BaseViewHolder viewHolder) {

    }

    @Override
    public void onBindViewHolder(D binding, int position, T bean) {

    }

    @Override
    public void onBindViewHolder(D binding, int position, BaseViewHolder viewHolder, T bean) {

    }

    @Override
    public void onViewDetachedFromWindow(D binding, BaseViewHolder viewHolder) {

    }

    @Override
    public void onViewAttachedToWindow(D binding, BaseViewHolder viewHolder) {

    }

    @Override
    public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, T bean) {

    }

    @Override
    public final boolean onItemClick(View view, BaseRVAdapter adapter, int onclickType, int itemType, int position, Object bean) {
        return super.onItemClick(view, adapter, onclickType, itemType, position, bean);
    }


}
